#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
int gval = 0;

int main()
{
    printf("我已经是一个进程! pid: %d,ppid: %d\n",getpid(),getppid());
    pid_t id = fork();

    if(id>0)
    {
        while(1)
        {
            printf("我是父进程，pid: %d,ppid: %d,ret id: %d,gval: %d\n",getpid(),getppid(),id,gval);
            sleep(1);
        }
    }
    else if(id==0)
    {
        while(1)
        {
            printf("我是子进程，pid: %d,ppid: %d,ret id: %d,gval: %d\n",getpid(),getppid(),id,gval);
            gval++;
            sleep(1);
        }
    }
    //(void)id;
    //printf("我是一个分支! pid: %d,ppid: %d\n",getpid(),getppid());
    //sleep(1);
    //chdir("/home/xiazelin/112"); 
    //FILE* fp = fopen("log.txt","w");
    //if(fp==NULL)
    //{
    //    perror("fopen");
    //    return 1;
    //}
    //pid_t pid = getppid();
    //pid_t id = getpid();
    //while(1)
    //{
    //    printf("hello bit,I am a process ,pid: %d , ppid: %d\n",id,pid);
    //    sleep(1);
    //}
    return 0;
}
